home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / SATcollision][ ƒ / SATcollision][.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  1.5 KB  |  65 lines  |  [TEXT/KAHL]

  1. /********************************/
  2. /********** SAT Collision ][ ***********/
  3. /********************************/
  4.  
  5. /*A more advanced version of SAT Collision, demonstrating the use of callback routines*/
  6. /*(hit task) for collision handling. What has happened is that the apples switch between*/
  7. /*good and bad, and we are not supposed to eat it when it's bad.*/
  8.  
  9. /*program SATcollisionII;*/
  10.  
  11. #include "SAT.h"
  12. #include "SATcollision][.h"
  13.  
  14.  
  15.  
  16.     WindowPtr    gameWind;
  17.     SpritePtr    ignoreSp;
  18.     long        l;
  19.     Point        p;
  20.  
  21. main()
  22. {
  23. /*Standard Inits.*/
  24.     MaxApplZone ();
  25.     FlushEvents (everyEvent - diskMask, 0 );
  26.     InitGraf (&thePort);
  27.     InitFonts ();
  28.     InitWindows ();
  29.     InitMenus ();
  30.     TEInit ();
  31.     InitDialogs (nil);        /* no restart proc */
  32.     InitCursor ();
  33.  
  34.     MoreMasters ();
  35.     MoreMasters ();
  36.  
  37.  
  38.     ConfigureSAT(true, VPositionSort, BackwardCollision, 32);
  39.     gameWind = InitSAT(128, 129, 512, 322);
  40.  
  41.     InitMrEgghead();
  42.     InitApple();
  43.  
  44.     ShowWindow(gameWind);
  45.     SelectWindow(gameWind);
  46.     PeekOffscreen();
  47.  
  48.     GetMouse(&p);
  49.     ignoreSp = NewSprite(0, p.h, p.v, &HandleMrEgghead, &SetupMrEgghead, &HitMrEgghead);
  50.     ignoreSp = NewSprite(0, 0, Rand(offSizeV - 32), &HandleApple, &SetupApple, &HitApple);
  51.  
  52.     HideCursor();
  53.  
  54.     while (!Button()) {
  55.         l = TickCount();
  56.         RunSAT(true);
  57. /*Start a new sprite once in a while.*/
  58.         if (Rand(40) == 1)
  59.             ignoreSp = NewSprite(0, 0, Rand(offSizeV - 32), &HandleApple, &SetupApple, &HitApple);
  60.         while (l > TickCount() - 2L) /*Maximize speed to 30 fps*/
  61.             ;
  62.     };
  63.     ShowCursor();
  64.     SATSoundShutup(); /*Always make sure the sound channel is de-allocated!*/
  65. }